package Model.Core.Impl;

import Factory.Entities.MessageFactory;
import Factory.Tip.TipsFactory;
import Model.Core.ICommunicatorEntity;
import Model.Core.IEntity;
import Model.Core.Tip.Tip;
import Model.Core.Tip.TipMoment;
import Model.Core.Tip.TipType;
import Model.Draw.Events.ManifestEntityDoneListener;
import java.util.List;

/**
 * Projeto de TCC: Editor de Diagramas de Comunicação em UML.
 * @author jose.luz
 */
public class MessageEntity implements IEntity {

    private String description;
    private LinkEntity parentLink;
    private ICommunicatorEntity targetEntity;
    private MessageFactory messageFactory;
    private List<Tip> tips;

    public MessageEntity() {
        //TODO: inject with spring.
        messageFactory = new MessageFactory();
        tips = TipsFactory.createMessageTips();
    }

    @Override
    public void manifestGraphically(Object sourceElement, Object targetElement) {
        messageFactory.createEntityGraphicalManifest(this, sourceElement, targetElement);
    }

    @Override
    public void addGraphicalManifestListener(ManifestEntityDoneListener listener) {
        messageFactory.addListener(listener);
    }

    @Override
    public void removeGraphicalManifestListener(ManifestEntityDoneListener listener) {
        messageFactory.removeListener(listener);
    }

    @Override
    public void select() {
        //TODO: implement this
    }

    @Override
    public Tip findTipBy(TipType type, TipMoment moment) {
        for (Tip tip : tips) {
            if (tip.getType() == type && tip.getMoment() == moment) {
                return tip;
            }
        }
        return null;
    }
    
    @Override
    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }
    
    public LinkEntity getParentLink() {
        return parentLink;
    }

    public void setParentLink(LinkEntity parentLink) {
        this.parentLink = parentLink;
    }

    public ICommunicatorEntity getTargetEntity() {
        return targetEntity;
    }

    public void setTargetEntity(ICommunicatorEntity targetEntity) {
        this.targetEntity = targetEntity;
    }    
}